/**
 * 配置
 * */
package org.zmhhxl.api.auth.domain.entity.mapper;

/**
 * UserInfo结构映射
 *
 * @author felord.cn
 * @since 1.0.0
 */
//@Mapper(componentModel = MappingConstants.ComponentModel.SPRING,  //使用依赖注入方式获取
//       unmappedTargetPolicy = ReportingPolicy.IGNORE,  //忽略未映射的属性
//       nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS,  //空值检查
//       //uses = {RoleMapper.class}
//       unmappedSourcePolicy = ReportingPolicy.IGNORE  //忽略未映射的属性
//)
//public interface UserInfoMapper {
//    /**
//     * 实体转DTO
//     *
//     * @param userInfo the user info
//     * @return the user info dto
//     */
//    @Mappings({
//          @Mapping(target = "thirdPartyUserIds", ignore = true),
//          @Mapping(target = "roleIds", ignore = true),
//    }) default UserInfoDTO toDTO(UserInfo userInfo){
//        return new UserInfoDTO(userInfo.getId(), userInfo.getUsername(), userInfo.getPassword(),
//              userInfo.isEnabled(), userInfo.getPhone(), userInfo.getEmail(), userInfo.getAvatarUrl(),
//              userInfo.getRealName(), userInfo.getNickName(), userInfo.getGender(), userInfo.getAddress(),
//              userInfo.getBirthday(), userInfo.getDescription(),
//              userInfo.getAuthorities().stream().map(Role::getId).collect(Collectors.toSet()),
//              userInfo.getThirdPartyUsers().stream().map(ThirdPartyUser::getId).collect(Collectors.toSet())
//              );
//    };
//
//    /**
//     * DTO转实体
//     *
//     * @param userInfoDTO the user info dto
//     * @return the user info
//     */
//    @Mappings({                                                //converter = @Qualifier , dateFormat = "yyyy-MM-dd HH:mm:ss"
//          @Mapping(target = "updateTime", source = "updateTime", qualifiedByName = ("localDateTimeToInstant")),
//          @Mapping(target = "authorities", ignore = true),
//          @Mapping(target = "thirdPartyUsers", ignore = true),
//    })
//    UserInfo toEntity(UserInfoDTO userInfoDTO);
//
//    @Named("localDateTimeToInstant")
//    default Instant localDateTimeToInstant(LocalDateTime localDateTime) {
//        return Optional.ofNullable(localDateTime)
//                .map(ldt -> ldt.atZone(ZoneId.systemDefault()).toInstant())
//                .orElse(null);
//    }
//
//    @Named("instantToLocalDateTime")
//    default LocalDateTime instantToLocalDateTime(Instant instant) {
//        return Optional.ofNullable(instant)
//                .map(i -> i.atZone(ZoneId.systemDefault()).toLocalDateTime())
//                .orElse(null);
//    }
//
//    /**
//     * 合并内容
//     *
//     * @param source 源
//     * @param target 目标
//     */
//    @BeanMapping(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE)
//    @Mappings(value = {
//          @Mapping(target = "password", ignore = true),
//          @Mapping(target = "authorities", ignore = true),
//          @Mapping(target = "thirdPartyUsers", ignore = true),
//    })
//    void mergeIgnorePasswordAndAuthorities(UserInfo source, @MappingTarget UserInfo target);
//
//    /**
//     * Merge.
//     *
//     * @param source the source
//     * @param target the target
//     */
//    @BeanMapping(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE)
//    @Mappings(value = {
//          @Mapping(target = "authorities", ignore = true),
//          @Mapping(target = "thirdPartyUsers", ignore = true),
//    })
//    void mergeIgnoreAuthorities(UserInfo source, @MappingTarget UserInfo target);
//
////    @Mapping(target = "username", ignore = true)  // 忽略字段不一致
////    @Mapping(target = "updateTime", ignore = true)  // 忽略字段不一致
////    @Mapping(target = "nickName", ignore = true)
////    @Mapping(target = "enabled", ignore = true)
////    @Mapping(target = "createTime", ignore = true)
////    @Mapping(target = "avatarUrl", ignore = true)
////    @Mapping(target = "authorities", ignore = true)
////    @BeanMapping(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE)
////    void toUserInfo(UserInfoDTO userInfoDTO, @MappingTarget UserInfo target);
//}
